package com.stu.thread.testlst;

import org.nustaq.serialization.FSTClazzInfo;
import org.nustaq.serialization.FSTObjectOutput;
import org.nustaq.serialization.util.FSTUtil;

import java.io.IOException;
import java.util.EnumSet;

/**
 * @projectName: learn_used_code
 * @packageName: com.stu.thread.testlst
 * @className: com.stu.thread.testlst-> TestLst
 * @createDate: 2022-01-14 14:30
 * @author: ZhangSheng
 * @version: 1.0
 * @description:
 */
public class TestLst {

    public static void main(String[] args) {
        String aPackage = FSTUtil.getPackage(TestLst.class);
        System.out.println(aPackage);
    }

    public void writeObject(FSTObjectOutput out, Object toWrite, FSTClazzInfo clzInfo, FSTClazzInfo.FSTFieldInfo referencedBy, int streamPosition) throws IOException {
        EnumSet enset = (EnumSet) toWrite;
        int count = 0;
        out.writeInt(enset.size());
        if ( enset.isEmpty() ) {
            EnumSet compl = EnumSet.complementOf(enset);
            out.writeClassTag(FSTUtil.getRealEnumClass(compl.iterator().next().getClass()));
        } else {
            for (Object element : enset) {
                if ( count == 0 ) {
                    out.writeClassTag(FSTUtil.getRealEnumClass(element.getClass()));
                }
                out.writeObjectInternal(element, null, Enum.class);
                count++;
            }
        }
    }


}
